package com.bss.dao;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.andy.basics.Dao;
import com.bss.model.Bed;
import com.bss.model.Patient;

@Repository
public class BedDao extends Dao<Bed> {

	public Patient findCurrent(Bed bed) {
		Query q = this
				.getEntityManager()
				.createQuery(
						"Select p from Patient p join p.admissions as a join a.bedBookings as bb where bb.checkOutDate is null and bb.bed.id =? ");
		q.setParameter(1, bed.getId());
		List<Patient> patients = q.getResultList();
		return patients.get(0);
	}
}
